package com.bungarus.test;

import com.bungarus.codec.protobuf.MessageProtobuf;

/**
 * Test case for message from one client
 */
public class AccessTestClient2 extends AbstractAccessTestClient{

    public static void main(String[] args) throws Exception {
        new AccessTestClient2().run(System.getProperty("access"));
    }

    /**
     * Test for login and IM message
     * type "login" in command line to login and get session id, and type other string to send IM message
     * type "logout" in command line to logout
     * asume that the current user data is {"accountName":"username2","password":"password2","tenantId":"10000","id":1002}
     * asume the current user send message to himself, so you will receive message sent by yourself
     */
    protected void run(String accessPoint)  {
        connectServer(accessPoint);
        while (true){
            String line = getInputString();
            MessageProtobuf.Message message;
            if(line.equalsIgnoreCase("login")) { //login
                message = TestClientMessageBuilder.buildLoginMessage(
                        "abc124",
                        "1002",
                        10000,
                        "Apo",
                        "Device",
                        "username2",
                        "password2"
                );
            }
            else if(line.equalsIgnoreCase("logout")) { // logout
                message = TestClientMessageBuilder.buildLogoutMessage(
                        loggedInUser,
                        "Apo",
                        "Device"
                );
            }
            else { // IM message
                message = TestClientMessageBuilder.buildIMMessage(
                        String.valueOf(System.currentTimeMillis()),
                        loggedInUser,
                        "1001",
                        "Apo",
                        "Device",
                        line
                );
            }
            // sending
            send(message);
        }
    }

}
